<template>
  <div class="t_pagination_select">
    <el-select
      v-model="childSelectedValue"
      @change="(val) => $emit('change',val)"
      :style="{width: width||'100%'}"
      v-bind="attrs"
      v-on="$listeners"
    >
      <el-option
        v-for="item in optionSource"
        :key="item[valueKey]"
        :label="item[labelKey]"
        :value="item[valueKey]"
      ></el-option>
      <!--<el-pagination
        small
        layout="total,prev, pager, next"
        @current-change="(val) => $emit('page-change',val)"
        :hide-on-single-page="true"
        :page-size="paginationOption.pageSize"
        :current-page="paginationOption.currentPage"
        :pager-count="paginationOption.pagerCount"
        :total="paginationOption.total"
      ></el-pagination>-->

      <el-pagination
        :background="background"
        :current-page.sync="currentPage"
        :page-size.sync="pageSize"
        :layout="layout"
        :page-sizes="pageSizes"
        :total="total"
        v-bind="$attrs"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </el-select>
  </div>
</template>

<script>

export default {
  name: 'TPaginationSelect',
  props: {
    value: {
      type: [String, Number]
    },
    // 选择框宽度
    width: {
      type: String
    },
    // 传入的option数组中，要作为最终选择项的键值名称
    valueKey: {
      type: String
    },
    // 传入的option数组中，要作为显示项的键值名称
    labelKey: {
      type: String
    },
    // 下拉框组件数据源
    optionSource: {
      type: Array
    },
    total: {
      required: true,
      type: Number
    },
    page: {
      type: Number,
      default: 1
    },
    limit: {
      type: Number,
      default: 20
    },
    pageSizes: {
      type: Array,
      default() {
        return [5, 10]
      }
    },
    layout: {
      type: String,
      default: 'total, sizes, prev, pager, next, jumper'
    },
    background: {
      type: Boolean,
      default: true
    },
    autoScroll: {
      type: Boolean,
      default: true
    },
    hidden: {
      type: Boolean,
      default: false
    }
  },
  created() {
    console.log("paginationOption",this.paginationOption)
  },
  computed: {
    childSelectedValue: {
      get () {
        return this.value
      },
      set (val) {
        this.$emit('input', val)
      }
    },
    attrs () {
      return {
        'popper-append-to-body': false,
        clearable: true,
        filterable: true,
        ...this.$attrs
      }
    },

    currentPage: {
      get() {
        return this.page
      },
      set(val) {
        this.$emit('update:page', val)
      }
    },
    pageSize: {
      get() {
        return this.limit
      },
      set(val) {
        this.$emit('update:limit', val)
      }
    }
  },
  methods:{
    handleSizeChange(val) {
      this.$emit('getList', { page: this.currentPage, limit: val })

    },
    handleCurrentChange(val) {
      this.$emit('getList', { page: val, limit: this.pageSize })
    }
  },
  watch: {
    childSelectedValue (val) {
      this.childSelectedValue = val
    }
  }
}
</script>
 <style lang="scss" scoped>
.t_pagination_select {
  ::v-deep .el-pagination {
    display: flex;
    margin-top: 10px;
    margin-left: 5px;
    background-color: #fff;
    align-items: center;
    .el-pager {
      display: flex;
      align-items: center;
    }
    .el-input__inner{

    }
  }
}
</style>
